# coding: utf-8
import json
from redis import Redis
from pymongo import MongoClient


class Tuniu:
    def __init__(self):
        self.redis_cli = Redis('192.168.0.1', 6379, 0)
        self.mongo_cli = MongoClient('127.0.0.1', 27017)
        self.db = self.mongo_cli['Tuniu']
        self.col = self.db['tuniu']
        self.rediskey = 'tuniu:items'

    def run(self):
        while True:
            _source, _data = self.redis_cli.blpop(self.rediskey)
            _dict_data = json.loads(_data.decode())
            self.col.insert(_dict_data)


def main():
    tn = Tuniu()
    tn.run()


if __name__ == '__main__':
    main()
